package com.geostar.constructionland.statistics.service.factory.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.geostar.constructionland.common.entity.statistics.UnifiedDataQueryConfig;
import com.geostar.constructionland.statistics.mapping.QueryMappedStatement;
import com.geostar.constructionland.statistics.service.factory.IParamsCustomWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;

/**
 * @Author makoto_zhu
 * @Date 2020-12-18 04:06:31
 * @Description
 **/
@Component
public class ParamsCustomWorkerImpl implements IParamsCustomWorker {
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void createParams(QueryMappedStatement statement, UnifiedDataQueryConfig unifiedDataQueryConfig) {
        HashMap hashMap = null;
        try {
            hashMap = objectMapper.readValue(unifiedDataQueryConfig.getParams(), HashMap.class);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("query param is not valid JSON string , Please check it. QueryParam:" + unifiedDataQueryConfig.getParams());
        }
        statement.setQueryParam(hashMap);
    }
}
